package com.sicong.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 全局访问权限拦截
 *
 * @author chenww
 * @date 2020-11-28
 */
@Component
public class WebAuthenticationFilter implements GlobalFilter, Ordered {

    @Override
    public int getOrder() {
        return -99999;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 移除请求头中的"Inner"参数
        exchange.getRequest().mutate().headers(httpHeaders -> httpHeaders.remove("Inner")).build();
        return chain.filter(exchange);
    }

}
